from flask import Blueprint,request,jsonify
from utils.db import db




import json



bp_work = Blueprint('workl', __name__)

@bp_work.route('/add/',methods=['POST',"GET","DELETE"])
def add():
    #添加工作流
    if request.method =="POST":
        #判断数据是什么传播过来的 然后怎么接收
        data = request.data
        if data:
            data = json.loads(request.data)
        else:
            data = request.form
        sql = "insert into workflow(`id`,`name`) values(%d,'%s') " % (0,data['name'])
        db.insert(sql)

        return jsonify({'code':200})

    #获取工作流进行展示
    elif request.method =="GET":
        sql = "select * from workflow"
        #获取全部信息
        res = db.find_all(sql)

        #retur 返回的只有字符串  不能返回结构 所以用jsonify
        return jsonify({'code':200,'list':res})
    else:
        pass
